<template>
  <div>
    <div class="herdertop">
      <img src="../../assets/top.png" alt="" class="topImg" />
      <el-breadcrumb separator="/">
        <el-breadcrumb-item>员工管理</el-breadcrumb-item>
        <el-breadcrumb-item>员工出勤记录</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="center" style="padding-top: 0px;">
      <div class="hander">员工出勤记录</div>
      <div class="orderList">
        <div class="entirety">
          <div>
            <div class="search">
              <!--  账号状态搜索信息 -->
              <div class="demo-input-suffix">
                城市
                <el-select
                  v-model="subRgCode"
                  @change="busstwo"
                  placeholder="请选择"
                  style="width: 65%"
                >
                  <el-option
                    v-for="item in communityList"
                    :key="item.cityCode"
                    :label="item.cityName"
                    :value="item.cityCode"
                  >
                  </el-option>
                </el-select>
              </div>
              <div class="demo-input-suffix">
                商圈
                <el-select
                  v-model="communityCode"
                  placeholder="请选择"
                  style="width: 60%"
                  :disabled="subRgCode === ''"
                >
                  <el-option
                    v-for="item in business"
                    :key="item.businessAreaCode"
                    :label="item.businessAreaName"
                    :value="item.businessAreaCode"
                  >
                  </el-option>
                </el-select>
              </div>
              <div class="demo-input-suffix">
                占用类型
                <el-select
                  style="width: 60%"
                  v-model="takeUpType"
                  placeholder="请选择"
                >
                  <el-option label="出勤类" value="0"></el-option>

                  <el-option label="缺勤类" value="1"></el-option>
                </el-select>
              </div>
              <div class="demo-input-suffix">
                占用原因
                <el-select
                  style="width: 60%"
                  v-model="takeUpReason"
                  placeholder="请选择"
                >
                  <el-option label="请假" value="0"></el-option>

                  <el-option label="调休" value="1"></el-option>
                  <el-option label="培训" value="2"></el-option>
                  <el-option label="开会" value="3"></el-option>
                  <el-option label="其它" value="4"></el-option>
                </el-select>
              </div>
              <div class="demo-input-suffix">
                <el-button
                  style="background-color:#fd804c;color: #fff;"
                  @click="downloadNew"
                  :disabled="tableData.length == 0 ? true : false"
                  >导出数据</el-button
                >
              </div>
            </div>
            <div class="top">
              <!--  账号状态搜索信息 -->
              <div class="demo-input-suffix">
                <el-date-picker
                  v-model="TimeLIst"
                  style="80%"
                  type="datetimerange"
                  range-separator="至"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期"
                  prefix-icon="el-icon-date"
                  clear-icon="el-icon-close"
                  :editable="false"
                >
                </el-date-picker>
              </div>
              <!--  账号状态搜索信息 -->
              <div class="demo-input-suffix">
                姓名
                <el-input
                  v-model="realName"
                  placeholder="输入姓名"
                  clearable
                  style="width: 55%"
                ></el-input>
              </div>
              <div class="demo-input-suffix" style="margin-left:-50px">
                手机号
                <el-input
                  v-model="phone"
                  clearable
                  style="width: 58%"
                  placeholder="输入手机号"
                ></el-input>
              </div>
              <div class="demo-input-suffix" style="margin-left:-50px">
                <el-button
                  style="background-color:#fd804c;color: #fff;"
                  @click.native.prevent="isSelect"
                  >查询</el-button
                >
                <el-button type="warning" @click.native.prevent="isEmpty"
                  >清空</el-button
                >
              </div>
            </div>
          </div>
        </div>
        <!--  员工出勤记录列表栏位-->
        <div class="entirety">
          <div class="footer">
            <el-table :data="tableData" style="width: 100%">
              <el-table-column prop="staffCode" label="员工编号">
                <template slot-scope="scope">
                  {{ scope.row.staffCode }}
                </template>
              </el-table-column>
              <el-table-column prop="realName" label="姓名">
                <template slot-scope="scope">
                  {{ scope.row.realName }}
                </template>
              </el-table-column>

              <el-table-column prop="phone" label="手机号">
                <template slot-scope="scope">
                  {{ scope.row.phone }}
                </template>
              </el-table-column>
              <el-table-column prop="cityName" label="归属城市">
                <template slot-scope="scope">
                  <div>
                    {{ scope.row.cityName }}
                  </div>
                </template>
              </el-table-column>
              <el-table-column prop="businessAreaName" label="商圈">
                <template slot-scope="scope">
                  {{ scope.row.businessAreaName }}
                </template>
              </el-table-column>
              <el-table-column prop="restDay" label="休息日">
                <template slot-scope="scope">
                  {{
                    scope.row.restDay == 0
                      ? "周日"
                      : scope.row.restDay == 1
                      ? "周一"
                      : scope.row.restDay == 2
                      ? "周二"
                      : scope.row.restDay == 3
                      ? "周三"
                      : scope.row.restDay == 4
                      ? "周四"
                      : scope.row.restDay == 5
                      ? "周五"
                      : scope.row.restDay == 6
                      ? "周六"
                      : ""
                  }}
                </template>
              </el-table-column>
              <el-table-column prop="startTimeLeave" label="请假时间">
                <template slot-scope="scope">
                  <div>
                    {{ scope.row.startTimeLeave }}- {{ scope.row.endTimeLeave }}
                  </div>
                </template>
              </el-table-column>
              <el-table-column prop="takeUpType" label="占用类型">
                <template slot-scope="scope">
                  {{ scope.row.takeUpType == 0 ? "出勤类" : "缺勤类" }}
                </template>
              </el-table-column>

              <el-table-column prop="takeUpReason" label="占用原因">
                <template slot-scope="scope">
                  {{
                    scope.row.takeUpReason == 0
                      ? "请假"
                      : scope.row.takeUpReason == 1
                      ? "调休"
                      : scope.row.takeUpReason == 2
                      ? "培训"
                      : scope.row.takeUpReason == 3
                      ? "开会"
                      : "其他"
                  }}
                </template>
              </el-table-column>
              <el-table-column prop="condition" label="状态">
                <template slot-scope="scope">
                  {{ scope.row.condition }}
                </template>
              </el-table-column>
              <el-table-column
                prop="remark"
                label="备注"
                :show-overflow-tooltip="true"
              >
                <template slot-scope="scope">
                  {{ scope.row.remark }}
                  <!-- { scope.row.remark.length > 20? scope.row.remark.slice(0, 20) + '...' : scope.row.remark}} -->
                </template>
              </el-table-column>

              <el-table-column fixed="right" label="操作">
                <template slot-scope="scope">
                  <div v-if="scope.row.operation == 1">
                    <el-button
                      @click.native.prevent="isCancel(scope.row)"
                      style="color: #fc9e76;"
                      type="text"
                      size="small"
                    >
                      取消
                    </el-button>
                  </div>
                  <div v-else>
                    <el-button
                      :disabled="true"
                      @click.native.prevent="isCancel(scope.row)"
                      style="color: #cccccc;"
                      type="text"
                      size="small"
                    >
                      取消
                    </el-button>
                  </div>
                </template>
              </el-table-column>
            </el-table>
            <div class="block">
              <div class="left"></div>
              <div class="right">
                <el-pagination
                  layout="total, sizes, prev, pager, next, jumper"
                  class="page"
                  @size-change="sizeChangeHandle"
                  @current-change="currentChangeHandle"
                  :current-page="pageIndex"
                  :page-size="pageSize"
                  :total="total"
                >
                </el-pagination>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import moment from "moment";

export default {
  data() {
    return {
      endTime: "",
      startTime: "",
      pageIndex: 1,
      pageSize: 20,
      total: 0,
      tableData: [],
      id: "",
      TimeLIst: [],
      subRgCode: "",
      communityCode: "",
      takeUpType: "",
      takeUpReason: "",
      realName: "",
      phone: "",
      communityList: [],
      business: []
    };
  },
  activated() {
    this.DetailByPage();

    this.isEmpty();

    this.fetchRegionCommunityList();
  },

  methods: {
    // 更换
    busstwo(val) {
      if (val == "") {
        this.communityCode = "";
      }
      // 监听城市的选择 筛选商圈的枚举
      if (val) {
        let businessArray = [];
        businessArray = this.communityList.find(item => item.cityCode === val)
          .businessCityInfo;
        if (businessArray) {
          this.business = businessArray;
          this.communityCode = "";
        }
      }
    },
    isSelect() {
      (this.pageIndex = 1), (this.pageSize = 20), this.DetailByPage();
    },
    isEmpty() {
      (this.endTime = ""),
        (this.startTime = ""),
        (this.pageIndex = 1),
        (this.pageSize = 20),
        (this.total = 0),
        (this.id = ""),
        (this.TimeLIst = []),
        (this.subRgCode = ""),
        (this.communityCode = ""),
        (this.takeUpType = ""),
        (this.takeUpReason = ""),
        (this.realName = ""),
        (this.phone = ""),
        (this.business = []);

      this.DetailByPage();
    },
    //详情
    isCancel(data) {
      this.$confirm("是否取消?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.$http({
            url: `/staffadmin/staffStatistics/cancelStaffAskVacation`,
            method: "POST",
            data
          }).then(res => {
            if (res.success != 1) {
              this.$message.error(res.error);
            } else {
              this.$message.success("取消成功");

              this.DetailByPage();
            }
          });
        })
        .catch(() => {
          this.$message.error("取消失败");
        });
      this.DetailByPage();
    },

    //导出
    downloadNew() {
      let startTime =
        moment(this.TimeLIst && this.TimeLIst[0]).format(
          "YYYY-MM-DD HH:mm:ss"
        ) || "";
      const endTime =
        moment(this.TimeLIst && this.TimeLIst[1]).format(
          "YYYY-MM-DD HH:mm:ss"
        ) || "";

      if (window.location.host == "hs.xstarlife.com") {
        window.location.href = `https://hs.xstarlife.com/api/staffadmin/staffStatistics/downloadStaffAskVacation?startTime=${startTime}&endTime=${endTime}&takeUpType=${
          this.takeUpType
        }&takeUpReason=${this.takeUpReason}&realName=${this.realName}&phone=${
          this.phone
        }&businessAreaCode=${this.communityCode}&businessAreaCode=${
          this.communityCode
        }&cityCode=${this.subRgCode}&size=${this.total}&page=${1}`;
      } else {
        window.location.href = `https://m.goltestarlife.com/staffadmin/staffStatistics/downloadStaffAskVacation?startTime=${startTime}&endTime=${endTime}&takeUpType=${
          this.takeUpType
        }&takeUpReason=${this.takeUpReason}&realName=${this.realName}&phone=${
          this.phone
        }&businessAreaCode=${this.communityCode}&businessAreaCode=${
          this.communityCode
        }&cityCode=${this.subRgCode}&size=${this.total}&page=${1}`;
      }
    },

    //分页获取优惠券模板列表接口调用
    DetailByPage() {
      this.$http({
        url: `/staffadmin/staffStatistics/staffAskVacationStatistics`,
        method: "GET",
        params: {
          takeUpType: this.takeUpType,

          takeUpReason: this.takeUpReason,
          realName: this.realName,
          phone: this.phone,

          businessAreaCode: this.communityCode,
          cityCode: this.subRgCode,
          startTime:
            this.TimeLIst && this.TimeLIst[0]
              ? moment(this.TimeLIst && this.TimeLIst[0]).format(
                  "YYYY-MM-DD HH:mm:ss"
                )
              : "",
          endTime:
            this.TimeLIst && this.TimeLIst[1]
              ? moment(this.TimeLIst && this.TimeLIst[1]).format(
                  "YYYY-MM-DD HH:mm:ss"
                )
              : "",
          size: this.pageSize,
          page: this.pageIndex
        }
      }).then(res => {
        this.tableData = res.list;
        //  [
        //           {
        //             businessAreaName: "",
        //             cityName: "",
        //             condition: "",
        //             endTimeLeave: "",
        //             id: 0,
        //             operation: 0,
        //             phone: "",
        //             realName: "",
        //             remark:
        //               "怎么能把超出的文字隐藏，鼠标移上去之后显示全部？怎么能把超出的文字隐藏，鼠标移上去之后显示全部？怎么能把超出的文字隐藏，鼠标移上去之后显示全部？怎么能把超出的文字隐藏，鼠标移上去之后显示全部？怎么能把超出的文字隐藏，鼠标移上去之后显示全部？怎么能把超出的文字隐藏，鼠标移上去之后显示全部？怎么能把超出的文字隐藏，鼠标移上去之后显示全部？",
        //             restDay: "",
        //             staffCode: "",
        //             startTimeLeave: "",
        //             takeUpReason: "",
        //             takeUpType: ""
        //           }
        //         ];

        this.total = parseInt(res.total);
      });
    },

    fetchRegionCommunityList() {
      // 获取城市map
      this.$http({
        url: "/staffadmin/homeService/staffManager/fetchCityAndBusiness",
        method: "get"
      }).then(res => {
        this.communityList = res;
      });
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val;
      this.pageIndex = 1;

      this.DetailByPage();
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val;

      this.DetailByPage();
    }
  }
};
</script>
<style scoped lang="scss">
.hander {
  width: 100%;
  height: 50px;
  line-height: 50px;
  font-size: 20px;
  font-weight: 900;
}
.news {
  margin-left: 60%;
}
.orderList {
  background-color: #ebeef1;
  padding-right: 40px;
  padding-top: 1px;
  padding-bottom: 1px;
  display: block;
  font-size: 16px;
  border-radius: 20px;
  list-style-type: none;
}
.search {
  margin-bottom: 0px;
}
.page {
  margin-top: 15px;
}
.entirety {
  width: 100%;
  margin: 10px;
  height: 100%;
  padding: 10px;
  background-color: #fff;
  border-radius: 10px;
  display: flex;
  padding-left: 10px;
  .basic {
    font-size: 18px;
    font-weight: 900;
    margin-top: 2%;
    margin-bottom: 1%;
    margin-left: 1%;
  }
}
.overall {
  width: 100%;
  height: auto;
  display: flex;
  justify-content: space-between;
  margin-top: 3%;
  .left {
    width: 20%;
    height: auto;
  }
  .right {
    width: 80%;
    height: auto;
  }
}
.demo-input-suffix {
  margin-left: 1%;
}

.select {
  width: 65%;
  height: auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  .dialog-footer,
  .choice {
    margin-left: 2%;
  }
}
.top {
  margin: 10px;
  display: flex;
  justify-content: space-between;
}
.herdertop {
  height: 8vh;
  display: flex;
  align-items: center;
  padding: 0 20px;
  box-sizing: border-box;
}
.topImg {
  margin-right: 20px;
}
/deep/ .itemClass .el-form-item__content {
  width: 350px;
}
.userSearch {
  display: flex;
  /deep/ .el-input__inner {
    box-sizing: border-box;
    height: 40px;
    border-radius: 0;
    width: 132px;
    border: 1px solid #dcdfe6;
  }
  /deep/ .el-icon-arrow-up:before {
    position: relative;
    top: -4px;
  }
  /deep/ .el-button {
    height: 40px;
    border-radius: 0;
    background-color: #fff;
    border: 1px solid #dcdfe6;
    border-left: none;
    border-top-right-radius: 4px;
    border-bottom-right-radius: 4px;
    position: relative;
    .el-icon-search {
      position: absolute;
      left: 50%;
      top: 50%;
      transform: translate(-50%, -50%);
    }
  }
  /deep/ .el-input--suffix .el-input__inner {
    border-right: none;
  }
  /deep/ .el-input--suffix .el-input__inner {
    border-top-left-radius: 4px;
    border-bottom-left-radius: 4px;
  }
}
.selects {
  width: 55%;
  height: auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  .dialog-footer,
  .choice {
    margin-left: 2%;
  }
}

/deep/ .but {
  background: #fd7097;
  color: #fff;
  margin-bottom: 1%;
}
.footer {
  width: 100%;
  display: flex;
  overflow: hidden;
  flex-direction: column;
}
.block {
  width: 100%;
  height: 70px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-sizing: border-box;
  padding: 0 10px 0 10px;
}
.left {
  font-size: 15px;
}
</style>

<style>
.el-tooltip__popper {
  max-width: 20%;
}
.el-tooltip__popper,
.el-tooltip__popper.is-dark {
  background: rgb(48, 65, 86) !important;
  color: #fff !important;
  line-height: 30px;
}
</style>
